package com.molyfun.parents.activity.course.adapter;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.course.view.CourseFeedbackCellView;
import com.molyfun.parents.rest.bean.CourseFeedbackListResponse;
import com.molyfun.parents.rest.bean.CourseListResponse;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 */
public class CourseFeedbackListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;

    private List<CourseFeedbackListResponse.CourseFeedbackBean> mDataList;

    FragmentManager mFragmentManager;
    CourseListResponse.CourseBean mCourseBean;

    public CourseFeedbackListAdapter(Context mContext, FragmentManager fragmentManager) {
        this.mContext = mContext;
        this.mFragmentManager = fragmentManager;
    }

    public void clearAll() {
        if (mDataList != null) {
            this.mDataList.clear();
        }
        notifyDataSetChanged();
    }


    public void refreshData(CourseListResponse.CourseBean courseBean, List<CourseFeedbackListResponse.CourseFeedbackBean> courseBeanList) {
        this.mDataList = courseBeanList;
        this.mCourseBean = courseBean;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CourseFeedbackViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_course_feedback_cell, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CourseFeedbackViewHolder courseFeedbackViewHolder = (CourseFeedbackViewHolder) holder;
        courseFeedbackViewHolder.courseFeedbackCellView.initData(mDataList.get(position), mCourseBean, mFragmentManager);
    }

    class CourseFeedbackViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.course_feedback_cell_layout)
        public CourseFeedbackCellView courseFeedbackCellView;

        public CourseFeedbackViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

    @Override
    public int getItemCount() {
        if (mDataList == null) {
            return 0;
        }
        return mDataList.size();
    }

}
